<!DOCTYPE html>
<html lang="zh-CN">

<head>
  <meta charset="UTF-8">
  <meta name="author" content="wangbo">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>DOM</title>
  <style>
    img {
      width: 400px;
      height: 400px;
    }
  </style>
</head>

<body>
  <div></div>
  <img src="http://p1.music.126.net/A4oyg7nydQk9na3fCE7ZDg==/109951165421617285.jpg?imageView&quality=89" alt="" srcset="">
  <button onclick="myzuo()">向左</button>
  <button onclick="myclick()">向右</button>
  <script>
    var pic_arr = ["http://p1.music.126.net/A4oyg7nydQk9na3fCE7ZDg==/109951165421617285.jpg?imageView&quality=89",
        "http://p1.music.126.net/c27byhx3KVvCle1zykmH_A==/109951165421216056.jpg?imageView&quality=89",
        "http://p1.music.126.net/uU3uL1XvXk7UieISRivS2g==/109951165421640213.jpg?imageView&quality=89",
        "http://p1.music.126.net/Mot-Vbz3JxqI2zbLzye0lQ==/109951165421632886.jpg?imageView&quality=89",
        "http://p1.music.126.net/KLyKvFgCMO68juLWVCgD4A==/109951165421399234.jpg?imageView&quality=89"]
    var i = 0
    function myclick() {
      //  4  1,2,3,0,1,2,3,0,1,2
      i++
      var yu = i % pic_arr.length
      var imgEle = document.querySelector("img")
      imgEle.setAttribute("src", pic_arr[yu])
      
    }
    function myzuo() {
      i--
      if (i<0) {
        i = pic_arr.length-1
      }
      var yu = i % pic_arr.length
      var imgEle = document.querySelector("img")
      imgEle.setAttribute("src", pic_arr[yu])
    }
    myclick()
  </script>
</body>

</html>